package org.example.utils;

import cn.hutool.core.text.AntPathMatcher;

import java.util.List;

/**
 * 自定义字符串工具类
 */
public class StringUtils extends org.apache.commons.lang3.StringUtils {

    /**
     * 判断指定字符串是否匹配指定字符串列表中的任意一个字符串
     *
     * @param str
     * @param strList
     * @return
     */
    public static boolean matches(String str, List<String> strList) {
        if (isEmpty(str)) {
            return false;
        }
        for (String pattern : strList) {
            if (isMatches(pattern, str)) {
                return true;
            }
        }

        return false;
    }

    /**
     * @param pattern 匹配规则
     * @param str     被匹配的字符串
     * @return
     */
    public static boolean isMatches(String pattern, String str) {
        AntPathMatcher antPathMatcher = new AntPathMatcher();
        return antPathMatcher.match(pattern, str);
    }

    /**
     * 是否包含字符串
     *
     * @param str 验证字符串
     * @param strs 字符串组
     * @return 包含返回true
     */
    public static boolean inStringIgnoreCase(String str, String... strs)
    {
        if (str != null && strs != null)
        {
            for (String s : strs)
            {
                if (str.equalsIgnoreCase(trim(s)))
                {
                    return true;
                }
            }
        }
        return false;
    }

}
